/*创建一个文件，将自己的姓名、学号、以及
20个[60-100]范围的随机整数写入文件中；
然后从文件中读出所有的字符并打印。*/

#include <stdio.h>
#include<stdlib.h>

//往文件中写入数据
void WriteToFile(char fileName[])
{
	char myName[100] = "Name 1";
	char myStuNo[100] = "202220112010";

	FILE *myFile;
	myFile = fopen(fileName, "w");

	fprintf(myFile, "%s\n", myName);
	fputs(myStuNo, myFile);

	for (int i = 0; i < 20; i++)
	{
		int randNum = rand() % 40 + 60;
		fprintf(myFile, "%d\n", randNum);
	}

	fclose(myFile);
}

//从文件中读出字符
void ReadFromFile(char fileName[])
{
	FILE * readFile;
	readFile = fopen(fileName, "r");
	char readChar;
	do
	{
		readChar = fgetc(readFile);
		putchar(readChar);
	}
	while (readChar != EOF);//EOF表示文件结束

	fclose(readFile);
}
int main ( )
{
	char fname[100] = "myTxtFile.txt";
	WriteToFile(fname);
	ReadFromFile(fname);
}



